package com.example.project_springboot.controller;

import com.example.project_springboot.aop.Log;
import com.example.project_springboot.pojo.Dept;
import com.example.project_springboot.pojo.Result;
import com.example.project_springboot.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.io.SAXReader;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Console;
import java.util.List;

/**
 * 部门管理Controller
 */
@RestController
@Slf4j
@RequestMapping("/depts")
public class DeptController {
    @Resource
    DeptService deptService;

    @GetMapping
    public Result findAllDept(){
        List<Dept> dept = deptService.findAllDept();
        return Result.success(dept);
    }
    @DeleteMapping("/{id}")
    @Log
    public Result deleteById(@PathVariable Integer id ){
        deptService.deleteById(id);
        return Result.success();
    }
    @PostMapping
    @Log
    public Result insertDept(@RequestBody Dept dept){
        deptService.insertDept(dept);
        return Result.success(dept);
    }
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        Dept dept = deptService.selectById(id);
        return Result.success(dept);
    }
    @PutMapping
    @Log
    public Result update(@RequestBody Dept dept){
        deptService.update(dept);
        return Result.success();
    }
}
